import QRCode from 'qrcode';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// 创建测试图片目录
const testDir = path.join(__dirname, 'test-images');
if (!fs.existsSync(testDir)) {
  fs.mkdirSync(testDir, { recursive: true });
}

// 生成测试二维码
const testData = [
  { text: 'https://github.com', filename: 'qrcode-github.png' },
  { text: 'Hello World! 你好世界！', filename: 'qrcode-hello.png' },
  { text: 'https://www.example.com/test?id=12345', filename: 'qrcode-url.png' }
];

async function generateTestQRCodes() {
  console.log('🎨 正在生成测试二维码...\n');

  for (const item of testData) {
    const outputPath = path.join(testDir, item.filename);
    
    try {
      await QRCode.toFile(outputPath, item.text, {
        width: 300,
        margin: 2,
        color: {
          dark: '#000000',
          light: '#FFFFFF'
        }
      });
      
      console.log(`✅ 已生成: ${item.filename}`);
      console.log(`   内容: ${item.text}`);
      console.log(`   路径: ${outputPath}\n`);
    } catch (error) {
      console.error(`❌ 生成失败: ${item.filename}`, error.message);
    }
  }

  console.log('✨ 测试二维码生成完成！');
  console.log(`📁 保存位置: ${testDir}\n`);
}

generateTestQRCodes();

